package com.cykj.faceledtv.utils;

import android.text.TextUtils;
import android.util.Base64;

import java.io.FileOutputStream;

/**
 * @author jzh
 * @date 2019/05/11 10:06
 */
public class Base64Utils {

    /**
     * base64转file
     */
    public static String base64ToFile(String base64, String savePath) {
        if (TextUtils.isEmpty(savePath)) {
            return null;
        }
        byte[] buffer = Base64.decode(base64, Base64.DEFAULT);
        if (buffer == null) {
            return null;
        }
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(savePath);
            fos.write(buffer);
            fos.flush();
            return savePath;
        } catch (Exception e) {
            return null;
        } finally {
            if (fos != null) {
                try {
                    fos.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
